package se.thoka.twt.server.item;

import java.util.Collection;

import se.thoka.twt.shared.exceptions.NoSuchObjectException;
import se.thoka.twt.shared.item.ItemService;
import se.thoka.twt.shared.utils.HasId;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;

@SuppressWarnings("serial")
public abstract class ItemServiceImpl<T extends HasId, DS extends ItemService<T>> extends RemoteServiceServlet implements ItemService<T> {

	@Override
	public T insert(T entity) {
		return getDatastore().insert(entity);
	}

	@Override
	public T update(T entity) throws NoSuchObjectException {
		return getDatastore().update(entity);
	}

	@Override
	public void delete(T entity) {
		getDatastore().delete(entity);
	}

	@Override
	public Collection<T> selectAll() {
		return getDatastore().selectAll();
	}

	@Override
	public T selectById(String id) throws NoSuchObjectException {
		return getDatastore().selectById(id);
	}
	
	protected abstract DS getDatastore();
}
